/**
 * 添加或者修改页面
 */
var OrderInfoDlg = {
    data: {
        id: "",
        orderNum: "",
        starTime: "",
        endTime: "",
        howlong: "",
        cgId: "",
        cgStr: "",
        wp: "",
        phone: "",
        username: "",
        idCard: "",
        qid: "",
        yhje: "",
        yuanjia: "",
        shifu: "",
        paystate: "",
        state: "",
        createTime: "",
        payTime: "",
        del: "",
        uid: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    
    
    var ACT = {
    		gid:0,
    		sid:0
    }

    
    ACT.getxq = function(gid){
    	var ajax = new $ax(Feng.ctxPath + "/wxapi/getShequ?gid=" + gid);
        var data = ajax.start();
        var d = data.data
        var html = '<option value="0">请选择小区</option>'
        	
        for(var i=0;i<d.length;i++){
        	html += '<option value="'+d[i].id+'">'+d[i].name+'</option>'
        }
        console.log(html)
        $("#xq").html(html)
        
        form.render()
        
        console.log(data)
        
    }
    
    
    ACT.getcg = function(gid,sid){
    	var ajax = new $ax(Feng.ctxPath + "/wxapi/getCw?gid=" + gid+"&sid="+sid);
        var data = ajax.start();
        var d = data.data
        var html = '<option value="0">请选择仓格</option>'
        	
        for(var i=0;i<d.length;i++){
        	var end = d[i].end
        	
        	var dis = ''
        		
        	if(end==1){
        		dis = "disabled"
        	}
        	
        	html += '<option '+dis+'  value="'+d[i].id+'">'+d[i].num+'</option>'
        }
        console.log(html)
        $("#cgId").html(html)
        
        form.render()
        
        console.log(data)
        
    }


  //渲染时间选择框
    var laydate = layui.laydate;
    laydate.render({
        type: 'date',
        min:'0',
        elem: '#starTime' //指定元素
    });
    
  //渲染时间选择框
    var laydate1 = layui.laydate;
    laydate.render({
        type: 'date',
        min:'0',
        elem: '#endTime' //指定元素
    });

    
    form.on('select(xq)', function(data) {
        var sid = data.value;
        
        if(sid!=0){
        	ACT.sid = sid
        	ACT.getcg(ACT.gid,sid)
        }else{
        	$("#cgId").html('<option value="0">请选择仓格</option>')
        	form.render()
        }
    });




    form.on('select(gg)', function(data) {
        var gid = data.value;
        
        if(gid!=0){
        	ACT.gid = gid
        	ACT.getxq(gid)
        }else{
        	$("#xq").html('<option value="0">请选择小区</option>')
        	$("#cgId").html('<option value="0">请选择仓格</option>')
        	form.render()
        }
    });




    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/order/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});